/*
 DNN Content Builder - sourceforge.net/projects/dnncb
 Copyright (c) 2004-2008
 by Emerson Lopes (emersonlopes@gmail.com)

 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
 to permit persons to whom the Software is furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all copies or substantial portions 
 of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 DEALINGS IN THE SOFTWARE.
*/

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;

namespace DNNContentBuilder 
{
	[Serializable]
	public class MetaDataInfo 
	{
		// Entity member variables for database table epMetaData
		private Int32 mMetaDataId;
		private string mTitle;
		private string mPKValue;
		private string mStatus;
		private Int32 mTaxonomyId;
		private Int32 mFormDefinitionId;
		private DateTime mScheduleDate;
		private DateTime mCreationDate;
		private DateTime mPublishDate;
		private DateTime mExpireDate;
		private Int32 mDataConnectionID;
		private Int32 mUserID;
		private Int32 mPortalID;
		private Int32 mModuleID;
		private Int32 mHitCount;
        
		// Calculated Expression member variables for database table epMetaData
        
        
		// Entity properties for database table epMetaData
        
		public Int32 MetaDataId 
		{
			get { return mMetaDataId; }
			set { mMetaDataId = value; }
		}
        
		public string Title 
		{
			get { return mTitle; }
			set { mTitle = value; }
		}
        
		public string PKValue 
		{
			get { return mPKValue; }
			set { mPKValue = value; }
		}
        
 		public MetaDataStatus Status 
		{
			get
			{
				return (MetaDataStatus)TypeDescriptor.GetConverter(typeof(MetaDataStatus)).ConvertFromString(mStatus);
			}
			set
			{
				mStatus = TypeDescriptor.GetConverter(typeof(MetaDataStatus)).ConvertToString(value);
			}
		}

		public Int32 TaxonomyId 
		{
			get { return mTaxonomyId; }
			set { mTaxonomyId = value; }
		}
        
        public Int32 FormDefinitionId 
		{
			get { return mFormDefinitionId; }
			set { mFormDefinitionId = value; }
		}
                
		public DateTime ScheduleDate 
		{
			get { return mScheduleDate; }
			set { mScheduleDate = value; }
		}
        
		public DateTime PublishDate 
		{
			get { return mPublishDate; }
			set { mPublishDate = value; }
		}

		public DateTime ExpireDate
		{
			get { return mExpireDate; }
			set { mExpireDate = value; }
		}
        
		public DateTime CreationDate 
		{
			get { return mCreationDate; }
			set { mCreationDate = value; }
		}
        
        public Int32 DataConnectionID
		{
			get { return mDataConnectionID; }
			set { mDataConnectionID = value; }
		}
		
		public Int32 UserID 
		{
			get { return mUserID; }
			set { mUserID = value; }
		}
                
		public Int32 PortalID 
		{
			get { return mPortalID; }
			set { mPortalID = value; }
		}

		public Int32 ModuleID
		{
			get { return mModuleID; }
			set { mModuleID = value; }
		}

		public Int32 HitCount 
		{
			get { return mHitCount;	}
			set { mHitCount = value; }
		}

		public string InternalStatus
		{
			get
			{
				return mStatus;
			}
			set
			{
				mStatus = value;
			}
		}
	}
    
	public class MetaDataController : BaseController
	{
		public MetaDataController() : base() {}

		public MetaDataController(ConnectionProvider cp) : base(cp) {}
        
		public Int32 Add(MetaDataInfo MetaDataInfo) 
		{
			return base.GetDataProvider().MetaDataAdd(MetaDataInfo.Title, MetaDataInfo.PKValue, MetaDataInfo.InternalStatus, MetaDataInfo.TaxonomyId, MetaDataInfo.FormDefinitionId, MetaDataInfo.ScheduleDate, MetaDataInfo.DataConnectionID, MetaDataInfo.UserID, MetaDataInfo.PortalID, MetaDataInfo.PublishDate, MetaDataInfo.ExpireDate, MetaDataInfo.CreationDate);
		}
        
		public void Update(MetaDataInfo MetaDataInfo) 
		{
			base.GetDataProvider().MetaDataUpdate(MetaDataInfo.MetaDataId, MetaDataInfo.Title, MetaDataInfo.PKValue, MetaDataInfo.InternalStatus, MetaDataInfo.TaxonomyId, MetaDataInfo.FormDefinitionId, MetaDataInfo.ScheduleDate, MetaDataInfo.CreationDate, MetaDataInfo.DataConnectionID, MetaDataInfo.UserID, MetaDataInfo.PortalID, MetaDataInfo.PublishDate, MetaDataInfo.ExpireDate);
		}
        
		public void Delete(Int32 metaDataId) 
		{
			base.GetDataProvider().MetaDataDelete(metaDataId);
		}

		public void PublishScheduledContent(Int32 PortalID) 
		{
			base.GetDataProvider().MetaDataPublishScheduledContent(PortalID);
		}

		public void DeleteSchedule(Int32 metaDataId) 
		{
			base.GetDataProvider().MetaDataDeleteSchedule(metaDataId);
		}

		public MetaDataInfo GetItem(Int32 metaDataId) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataGet(metaDataId))
			{
				MetaDataInfo infoObject = (MetaDataInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(MetaDataInfo));
				return infoObject;
			} 
		}

		public MetaDataInfo GetItemAddingHit(string guid, string userRoles) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataGetAddingHit(guid, userRoles.ToUpper().Trim()))
			{
				MetaDataInfo infoObject = (MetaDataInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(MetaDataInfo));
				return infoObject;
			} 
		}

		// Select query methods for database table MetaData
		public ArrayList GetAllMetaData(Int32 PortalID) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataGetAllMetaData(PortalID))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}

		public ArrayList GetScheduledContent(Int32 PortalID, Int32 ModuleID) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataGetScheduledContent(PortalID, ModuleID))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}

		public MetaDataInfo GetMetaDataByPKValue(string pkValue, string userRoles)
		{
			using (IDataReader reader = base.GetDataProvider().MetaDataByPKValue(pkValue, userRoles.ToUpper().Trim()))
			{
				return (MetaDataInfo)DotNetNuke.Common.Utilities.CBO.FillObject(reader, typeof(MetaDataInfo));
			}
		}

		public ArrayList GetMetaDataByUser(Int32 PortalID, Int32 UserID) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataGetMetaDataByUser(PortalID, UserID))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}
        
		public ArrayList GetMoreRecentApprovedContent(Int32 portalId, Int32 formId, string userRoles)
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataGetMoreRecentApprovedContent(portalId, formId, userRoles))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}
        
		public ArrayList GetNotApprovedMetaDataByUser(Int32 PortalID, DateTime CreationDate, Int32 UserID) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataGetNotApprovedMetaDataByUser(PortalID, CreationDate, UserID))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}
        
		public ArrayList GetWorkingMetaDataByUser(Int32 PortalID, Int32 UserID) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataGetWorkingMetaDataByUser(PortalID, UserID))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}

		public ArrayList GetMostPopularItems(Int32 portalId, Int32 formId, Int32 rowCount, bool onlyPublished, string userRoles) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataGetMostPopularItems(portalId, formId, rowCount, onlyPublished, userRoles.ToUpper().Trim()))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}

        
		// Relation methods for database table epMetaData
		public ArrayList GetByFormDefinition(Int32 portalId, Int32 formId, Int32 rowCount, string where, string orderBy, string userRoles) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataByFormDefinition(portalId, formId, rowCount, where, orderBy, userRoles.ToUpper().Trim()))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}
		public ArrayList GetByTaxonomy(Int32 portalId, Int32 formId, Int32 taxonomyId, Int32 rowCount, string where, string orderBy, string userRoles) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataByTaxonomy(portalId, formId, taxonomyId, rowCount, where, orderBy, userRoles.ToUpper().Trim()))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}
															
		public ArrayList XRefByTaxonomy(Int32 portalId, Int32 formId, Int32 taxonomyId, Int32 rowCount, string where, string orderBy, string userRoles)
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataXRefByTaxonomy(portalId, formId, taxonomyId, rowCount, where, orderBy, userRoles.ToUpper().Trim()))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			}
		}

		public ArrayList GetByPortal(Int32 portalID) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataByPortal(portalID))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}
        
		public ArrayList GetByUser(Int32 userID) 
		{
			using (IDataReader idr = base.GetDataProvider().MetaDataByUser(userID))
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(MetaDataInfo));
				return infoList;
			} 
		}
	}
}
